package com.easybuilder.core.rbac.config;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @Author zhangxingshuai
 * @Description //TODO 认证成功处理器
 * @Date 15:04 2021/8/26
 * @Param
 * @return
 **/
@Component
public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
        response.setHeader("Authorization", "123456");
        response.setContentType("application/json");
        JSONObject result = new JSONObject();
        result.put("status", HttpStatus.OK.value());
        result.put("success", true);
        result.put("msg", "登陆成功");
        response.getWriter().write(result.toJSONString());
    }

    @Override
    public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {

    }

}
